package com.system.order.controller;


import com.system.order.enums.BizCodeEnum;
import com.system.order.request.ConfirmOrderRequest;
import com.system.order.service.ProductOrderService;
import com.system.order.util.JsonData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
public class OrderController {


    @Autowired
    private ProductOrderService orderService;
    /**
     * 查询订单状态
     *
     * 此接口没有登录拦截，可以增加一个秘钥进行rpc通信
     *
     * @param outTradeNo
     * @return
     */
    @GetMapping("query_state")
    public JsonData queryProductOrderState(@RequestParam("out_trade_no")String outTradeNo){

        String state = orderService.queryProductOrderState(outTradeNo);

        return StringUtils.isBlank(state)?JsonData.buildResult(BizCodeEnum.ORDER_CONFIRM_NOT_EXIST):JsonData.buildSuccess(state);

    }

    @PostMapping("confirm")
    public void confirmOrder(@RequestBody ConfirmOrderRequest orderRequest, HttpServletResponse response){
        JsonData jsonData = orderService.confirmOrder(orderRequest);
    }

}
